import java.sql.*;

class aufg51{
	public static void main(String[] args) {

		int gesPol=Integer.valueOf(args[0]).intValue();
		double transx = Double.valueOf(args[1]).doubleValue();
		double transy = Double.valueOf(args[2]).doubleValue();
		double transz = Double.valueOf(args[3]).doubleValue();
		translate(gesPol, transx, transy, transz);
	}

	public static void translate(int gesPol, double transx, double transy, double transz){
		try{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			String connectionUrl = "jdbc:sqlserver://edudat.informatik.uni-mainz.de;databaseName=DbSS2007_tnagel; user=StudSS2007_tnagel;password=NaT1625;";
			Connection con = DriverManager.getConnection(connectionUrl);
			Statement  st = null;
			Statement st2 = null;
			ResultSet  rs = null;
			st = con.createStatement();
			rs = st.executeQuery( "SELECT Distinct PktID,x,y,z FROM Punkte P, (SELECT * FROM( Kanten K JOIN Flaeche F ON F.FlachID IN (K.Flach1, K.Flach2))) tmp  WHERE P.PktID IN (tmp.Punkt1, tmp.Punkt2) AND tmp.PolyID='"+gesPol+"'" );
			while(rs.next()){
				//System.out.println( rs.getString( 1 )+" ; "+ rs.getString(2)+" ; "+ rs.getString(3)+" ; "+ rs.getString(4) );
				st2 = con.createStatement();
				String quest="UPDATE Punkte SET x = "+(Double.valueOf(rs.getString(2)).doubleValue()+transx)+",y = "+(Double.valueOf(rs.getString(3)).doubleValue()+transy)+", z = "+(Double.valueOf(rs.getString(4)).doubleValue()+transz)+" WHERE  PktID='"+Integer.valueOf(rs.getString(1)).intValue()+"'";
				//System.out.println(quest);
				try{
					st2.executeQuery (quest);
				}catch(Exception e){}
			}
			System.out.println("Ihre Aenderungen wurden vollzogen.");
		}catch( Exception e){System.out.println(e);} 
	}





}